// 输出笛卡尔乘积
#include <iostream>
#include <set>
#include <vector>
#include <cstring>

using namespace std;


vector<string> split(const string& str, const string& delim) {  
	vector<string> res;  
	if("" == str) return res;  
	//先将要切割的字符串从string类型转换为char*类型  
	char * strs = new char[str.length() + 1];
	strcpy(strs, str.c_str());   
 
	char * d = new char[delim.length() + 1];  
	strcpy(d, delim.c_str());  
 
	char *p = strtok(strs, d);  
	while(p) {  
		string s = p; //分割得到的字符串转换为string类型  
		res.push_back(s); //存入结果数组  
		p = strtok(NULL, d);  
	}  
 
	return res;  
}

set<string> input_set()
{
    string str;cin>>str;
    vector<string> v = split(str,"{,}");
    set<string> res(v.begin(),v.end());
    return res;
}


int main()
{
    set<string> s1 = input_set();
    set<string> s2 = input_set();
    cout<<"{";
    for(auto i:s1) {
        for(auto j:s2) {
            cout<<"<"<<i<<","<<j<<">";
            if(!(i == *s1.rbegin() && j == *s2.rbegin()))
                cout<<",";
        }
        
    }
    cout<<"}";
    return 0;
}
